package com.example.demo.leetcode;

/**
 * 链接 <a href="https://leetcode.cn/problems/reverse-bits/description/?envType=study-plan-v2&envId=top-interview-150">https://leetcode.cn/problems/reverse-bits/description/?envType=study-plan-v2&envId=top-interview-150</a>
 *
 * @author WangYX
 * @version 1.0.0
 * @date 2024/02/20 9:38
 */
public class _190_颠倒的二进制位 {
    public static void main(String[] args) {
        int i = reverseBits(-3);
        System.out.println(i);
    }

    public static int reverseBits(int n) {
        int res = 0;
        for (int i = 0; i < 32; i++) {
            res = (res << 1) | (n & 1);
            n >>= 1;
        }
        return res;
    }
}
